<template>
    <heards title="搜索"></heards>
    <van-search v-model="values" placeholder="请输入搜索关键词" />

    <van-card v-for="(v, i) in list2" :key="i" :price="v.goods_price" :title="v.goods_name" thumb="">
        <template #thumb>
            <van-image
                :src="v.goods_big_logo ? v.goods_big_logo : 'https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg'" />
        </template>
        <template #footer>
            <van-stepper v-model="v.num" />
        </template>
    </van-card>
    <van-submit-bar :price="price*1000" button-text="提交订单" @submit="onSubmit">
        <van-checkbox v-model="checked">全选</van-checkbox>
    </van-submit-bar>
</template>

<script setup>
import heards from '@/assets/heards.vue';
import { ref, watch } from 'vue'
import { searchApi } from '@/api/api';
let list2 = ref({})
const search = () => {
    searchApi().then((res) => {
        list2.value = res.data.message.goods
    })
}
search()

import _ from 'lodash'
let values = ref('')
//搜索
// watch(values, _.debounce((newValue, oldValue) => {
//     search()
// }, 500)
// )
watch(values,(newValue, oldValue) => {
    search()
},)

const price=()=>{
    let sum=0;
    list2.value.forEach((v) =>{
        sum+=v.num*v.goods_price
    });
    return sum
}
</script>

<style lang="scss" scoped></style>